<template>
  <el-card class="stats-card" :class="{ [`bg-${type}`]: type }">
    <div class="stats-content">
      <div class="stats-icon" v-if="icon">
        <i :class="icon"></i>
      </div>
      <div class="stats-info">
        <div class="stats-title">{{ title }}</div>
        <div class="stats-value">{{ value }}</div>
        <div class="stats-footer" v-if="footer">
          <span>{{ footer }}</span>
          <el-icon v-if="trend" :class="['trend-icon', `trend-${trend}`]">
            <component :is="trend === 'up' ? 'ArrowUp' : 'ArrowDown'" />
          </el-icon>
          <span v-if="percentage" class="percentage" :class="{ 'trend-up': trend === 'up', 'trend-down': trend === 'down' }">{{ percentage }}</span>
        </div>
      </div>
    </div>
  </el-card>
</template>

<script setup>
defineProps({
  title: {
    type: String,
    default: '统计标题'
  },
  value: {
    type: [String, Number],
    default: '0'
  },
  icon: {
    type: String,
    default: ''
  },
  type: {
    type: String,
    default: '',
    validator: (value) => {
      return ['', 'primary', 'success', 'warning', 'danger', 'info'].includes(value)
    }
  },
  trend: {
    type: String,
    default: '',
    validator: (value) => {
      return ['', 'up', 'down'].includes(value)
    }
  },
  percentage: {
    type: String,
    default: ''
  },
  footer: {
    type: String,
    default: ''
  }
})
</script>

<style scoped>
.stats-card {
  margin-bottom: 20px;
}

.stats-content {
  display: flex;
  align-items: center;
}

.stats-icon {
  font-size: 48px;
  margin-right: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  background-color: rgba(0, 0, 0, 0.04);
}

.stats-info {
  flex: 1;
}

.stats-title {
  font-size: 14px;
  color: #606266;
  margin-bottom: 8px;
}

.stats-value {
  font-size: 24px;
  font-weight: bold;
  line-height: 1;
  margin-bottom: 12px;
}

.stats-footer {
  font-size: 13px;
  color: #909399;
  display: flex;
  align-items: center;
}

.trend-icon {
  margin: 0 4px;
  font-size: 12px;
}

.percentage {
  font-weight: 500;
}

.trend-up {
  color: #67c23a;
}

.trend-down {
  color: #f56c6c;
}

/* 背景色样式 */
.bg-primary {
  background-color: var(--el-color-primary);
  color: white;
}

.bg-success {
  background-color: var(--el-color-success);
  color: white;
}

.bg-warning {
  background-color: var(--el-color-warning);
  color: white;
}

.bg-danger {
  background-color: var(--el-color-danger);
  color: white;
}

.bg-info {
  background-color: var(--el-color-info);
  color: white;
}

.bg-primary .stats-title,
.bg-success .stats-title,
.bg-warning .stats-title,
.bg-danger .stats-title,
.bg-info .stats-title,
.bg-primary .stats-footer,
.bg-success .stats-footer,
.bg-warning .stats-footer,
.bg-danger .stats-footer,
.bg-info .stats-footer {
  color: rgba(255, 255, 255, 0.8);
}

.bg-primary .stats-icon,
.bg-success .stats-icon,
.bg-warning .stats-icon,
.bg-danger .stats-icon,
.bg-info .stats-icon {
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
}
</style> 